package v;

import c.PacientesController;
import core.constructor.constructor;
import java.awt.ComponentOrientation;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.UIManager;
import tools.DatosComboBox;
import tools.Util;

public class Paciente_View_Add extends javax.swing.JPanel {

    constructor c;
    PacientesController controlador;
    DatosComboBox cbx;
    //Modo en que se debe de desplegar la Interfaz - INSERT - UPDATE - SELECT
    private String mod = "";
    private String llavePrimaria;
    //Corresponde al Nombre del Campo en la Base de Datos que es LlavePrimaria
    private String campoPK;
    private String noIdentificacion = "";
    private String idAcuediente = "";
    Util u = new Util(); //Instanciar Clase de Utilidades

    public Paciente_View_Add() {
    }

    public Paciente_View_Add(Object... e) {
        initComponents();

        controlador = new PacientesController();
        config(e);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jXTitledSeparator1 = new org.jdesktop.swingx.JXTitledSeparator();
        cNombreAcuediente = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        cTelAcuediente = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        cDirAcuediente = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        cbTipoDocumento = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        cIdentificacion = new javax.swing.JTextField();
        jXTitledSeparator2 = new org.jdesktop.swingx.JXTitledSeparator();
        jLabel5 = new javax.swing.JLabel();
        cNombres = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        cApellidos = new javax.swing.JTextField();
        jXTitledSeparator3 = new org.jdesktop.swingx.JXTitledSeparator();
        jLabel7 = new javax.swing.JLabel();
        cDireccion = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        cTelefono = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        cbDepto = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        cbCiudad = new javax.swing.JComboBox();
        jXTitledSeparator4 = new org.jdesktop.swingx.JXTitledSeparator();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        cReligion = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        cbSexo = new javax.swing.JComboBox();
        cFechaNacimiento = new org.jdesktop.swingx.JXDatePicker();
        jLabel15 = new javax.swing.JLabel();
        cFechaIngreso = new org.jdesktop.swingx.JXDatePicker();
        sEstrato = new javax.swing.JSpinner();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        cbParentesco = new javax.swing.JComboBox();
        jLabel18 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        bGuardar = new javax.swing.JButton();
        bClear = new javax.swing.JButton();
        bCancelar = new javax.swing.JButton();

        jXTitledSeparator1.setFont(new java.awt.Font("Tahoma", 1, 15)); // NOI18N
        jXTitledSeparator1.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        jXTitledSeparator1.setTitle("Acudiente");

        cNombreAcuediente.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel1.setText("Nombres");

        cTelAcuediente.setEditable(false);
        cTelAcuediente.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel2.setText("Telefono");

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        cDirAcuediente.setEditable(false);
        cDirAcuediente.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel3.setText("Dirección");

        cbTipoDocumento.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        cbTipoDocumento.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbTipoDocumentoItemStateChanged(evt);
            }
        });

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel11.setText("Tipo Documento");

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel4.setText("Numero Identificación");

        cIdentificacion.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jXTitledSeparator2.setFont(new java.awt.Font("Tahoma", 1, 15)); // NOI18N
        jXTitledSeparator2.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        jXTitledSeparator2.setTitle("Datos Generales");

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel5.setText("Nombres");

        cNombres.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel6.setText("Apellidos");

        cApellidos.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jXTitledSeparator3.setFont(new java.awt.Font("Tahoma", 1, 15)); // NOI18N
        jXTitledSeparator3.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        jXTitledSeparator3.setTitle("Datos Ubicación");

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel7.setText("Direccion");

        cDireccion.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel8.setText("Telefono");

        cTelefono.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel9.setText("Depto Residencia");

        cbDepto.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        cbDepto.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbDeptoItemStateChanged(evt);
            }
        });

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel10.setText("Ciudad Residencia");

        cbCiudad.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jXTitledSeparator4.setFont(new java.awt.Font("Tahoma", 1, 15)); // NOI18N
        jXTitledSeparator4.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        jXTitledSeparator4.setTitle("Otros Datos");

        jLabel12.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel12.setText("Fecha Nacimiento");

        jLabel13.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel13.setText("Religión");

        cReligion.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel14.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel14.setText("Sexo");

        cbSexo.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        cFechaNacimiento.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        cFechaNacimiento.setFormats("dd-MM-yyyy");

        jLabel15.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel15.setText("Fecha Ingreso");

        cFechaIngreso.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        cFechaIngreso.setFormats("dd-MM-yyyy");

        sEstrato.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        sEstrato.setModel(new javax.swing.SpinnerNumberModel(0, 0, 6, 1));

        jLabel16.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel16.setText("Estrato");

        jLabel17.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel17.setText("Parentesco");

        cbParentesco.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        cbParentesco.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbParentescoItemStateChanged(evt);
            }
        });

        jLabel18.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel18.setText("Foto Aqui");
        jLabel18.setBorder(new org.jdesktop.swingx.border.DropShadowBorder());

        jButton2.setText("Examinar");

        bGuardar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        bGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/guardar32.png"))); // NOI18N
        bGuardar.setText("Guardar");
        bGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bGuardarActionPerformed(evt);
            }
        });

        bClear.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        bClear.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/limpiar32.png"))); // NOI18N
        bClear.setText("Limpiar Campos");
        bClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bClearActionPerformed(evt);
            }
        });

        bCancelar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        bCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/core/img/cancelar32.png"))); // NOI18N
        bCancelar.setText("Cancelar");
        bCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bCancelarActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(jLabel18, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 118, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jButton2))
                            .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                        .add(layout.createSequentialGroup()
                                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                                .add(jLabel6)
                                                .add(jLabel4)
                                                .add(jLabel5)
                                                .add(jLabel11))
                                            .add(12, 12, 12)
                                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                                .add(cbTipoDocumento, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .add(cIdentificacion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 255, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(cNombres, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 255, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(org.jdesktop.layout.GroupLayout.TRAILING, cApellidos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 255, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                                        .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                            .add(jXTitledSeparator2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 394, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                            .add(5, 5, 5)))
                                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                        .add(jXTitledSeparator3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 399, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(layout.createSequentialGroup()
                                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                                .add(jLabel8)
                                                .add(jLabel7)
                                                .add(jLabel9))
                                            .add(35, 35, 35)
                                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                                .add(cDireccion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 259, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(cTelefono, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 259, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .add(cbDepto, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 259, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                                        .add(layout.createSequentialGroup()
                                            .add(jLabel10)
                                            .add(31, 31, 31)
                                            .add(cbCiudad, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                                .add(62, 62, 62)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jXTitledSeparator4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 399, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(layout.createSequentialGroup()
                                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                            .add(jLabel12)
                                            .add(jLabel15)
                                            .add(jLabel13)
                                            .add(jLabel16)
                                            .add(jLabel14))
                                        .add(35, 35, 35)
                                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                            .add(org.jdesktop.layout.GroupLayout.TRAILING, cbSexo, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .add(org.jdesktop.layout.GroupLayout.TRAILING, cReligion)
                                            .add(cFechaIngreso, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 257, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                            .add(cFechaNacimiento, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 257, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                            .add(org.jdesktop.layout.GroupLayout.TRAILING, sEstrato, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 257, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                                    .add(jXTitledSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 394, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                            .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 88, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                            .add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 88, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                            .add(jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 88, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                            .add(jLabel17, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 88, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                        .add(59, 59, 59)
                                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                                .add(cNombreAcuediente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 206, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                                .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                            .add(cDirAcuediente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 252, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                            .add(cbParentesco, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 252, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                            .add(cTelAcuediente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 252, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))))))
                    .add(layout.createSequentialGroup()
                        .add(165, 165, 165)
                        .add(bGuardar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 163, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(bClear, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 165, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(bCancelar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 164, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(24, 24, 24))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jButton2)
                    .add(jLabel18, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE))
                .add(30, 30, 30)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jXTitledSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jXTitledSeparator2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
                        .add(cbTipoDocumento, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(jLabel11)
                        .add(jLabel1)
                        .add(cNombreAcuediente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jButton1))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
                    .add(jLabel4)
                    .add(cIdentificacion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel2)
                    .add(cTelAcuediente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
                    .add(jLabel5)
                    .add(cNombres, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel3)
                    .add(cDirAcuediente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
                    .add(jLabel6)
                    .add(cApellidos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel17)
                    .add(cbParentesco, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
                    .add(jXTitledSeparator3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jXTitledSeparator4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(11, 11, 11)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
                    .add(jLabel7)
                    .add(cDireccion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(cFechaNacimiento, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel12))
                .add(9, 9, 9)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
                    .add(jLabel8)
                    .add(cTelefono, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel15)
                    .add(cFechaIngreso, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
                    .add(jLabel9)
                    .add(cbDepto, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel13)
                    .add(cReligion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
                    .add(jLabel10)
                    .add(cbCiudad, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel16)
                    .add(sEstrato, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(cbSexo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel14))
                .add(41, 41, 41)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE, false)
                    .add(bGuardar)
                    .add(bClear)
                    .add(bCancelar))
                .add(22, 22, 22))
        );
    }// </editor-fold>//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    //c.ventanaEmergente("SELECT id_acudiente,id_identificacion,nombres FROM acudiente", "CODIGO,CEDULA,NOMBRES", c , this.getClass().getName() , "cargar");

    SeleccionadorIU select = new SeleccionadorIU("SELECT id_acudiente,identificacion, UPPER(nombres ||' '|| apellidos) , telefono , UPPER(direccion) FROM acudiente WHERE estado = 1", "CODIGO,CEDULA,NOMBRES,TELEFONO,DIRECCION", c, this.getClass().getName(), "cargar");
    select.setVisible(true);
//    select.setBounds(20, 20, 453, 600);
    cargar(select.getDatosSelect());


}//GEN-LAST:event_jButton1ActionPerformed

private void cbTipoDocumentoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbTipoDocumentoItemStateChanged
// TODO add your handling code here:
}//GEN-LAST:event_cbTipoDocumentoItemStateChanged

private void cbDeptoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbDeptoItemStateChanged
    //Evento que afecta Combobox de Ciudades iniciado por ComboBox Departamentos
    cbCiudad.setModel(new javax.swing.DefaultComboBoxModel(cbx.cbCiudad(cbDepto)));
}//GEN-LAST:event_cbDeptoItemStateChanged

private void cbParentescoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbParentescoItemStateChanged
// TODO add your handling code here:
}//GEN-LAST:event_cbParentescoItemStateChanged

private void bGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bGuardarActionPerformed
    prepararTransaccion();
}//GEN-LAST:event_bGuardarActionPerformed

private void bCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bCancelarActionPerformed
    if (c != null) {
        c.ventPrincipal();
    } else {
        Logger.getLogger(Acudiente_View_Add.class.getName()).log(Level.WARNING, "La Clase Constructor no ha sido instanciada");
    }
}//GEN-LAST:event_bCancelarActionPerformed

    private void bClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bClearActionPerformed
        Util.limpiarCamposForm(this);
    }//GEN-LAST:event_bClearActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bCancelar;
    private javax.swing.JButton bClear;
    private javax.swing.JButton bGuardar;
    private javax.swing.JTextField cApellidos;
    private javax.swing.JTextField cDirAcuediente;
    private javax.swing.JTextField cDireccion;
    private org.jdesktop.swingx.JXDatePicker cFechaIngreso;
    private org.jdesktop.swingx.JXDatePicker cFechaNacimiento;
    private javax.swing.JTextField cIdentificacion;
    private javax.swing.JTextField cNombreAcuediente;
    private javax.swing.JTextField cNombres;
    private javax.swing.JTextField cReligion;
    private javax.swing.JTextField cTelAcuediente;
    private javax.swing.JTextField cTelefono;
    private javax.swing.JComboBox cbCiudad;
    private javax.swing.JComboBox cbDepto;
    private javax.swing.JComboBox cbParentesco;
    private javax.swing.JComboBox cbSexo;
    private javax.swing.JComboBox cbTipoDocumento;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private org.jdesktop.swingx.JXTitledSeparator jXTitledSeparator1;
    private org.jdesktop.swingx.JXTitledSeparator jXTitledSeparator2;
    private org.jdesktop.swingx.JXTitledSeparator jXTitledSeparator3;
    private org.jdesktop.swingx.JXTitledSeparator jXTitledSeparator4;
    private javax.swing.JSpinner sEstrato;
    // End of variables declaration//GEN-END:variables

    /**
     * <strong>config</strong><br> Configura los parametros que provienen del
     * constructor de la clase.<br> e[0] - contiene el JFrame 'padre'.
     *
     * @param e
     */
    private void config(Object... e) {
        if (e.length > 0) {
            try {
                c = (constructor) e[0];


                /// Dar Valor a Combobox
                cbx = new DatosComboBox();
                cbDepto.setModel(new javax.swing.DefaultComboBoxModel(cbx.cbDepartamento()));
                cbDepto.setSelectedItem("Valle del Cauca");
                cbCiudad.setModel(new javax.swing.DefaultComboBoxModel(cbx.cbCiudad(cbDepto)));
                cbSexo.setModel(new javax.swing.DefaultComboBoxModel(cbx.cbSexo()));
                cbTipoDocumento.setModel(new javax.swing.DefaultComboBoxModel(cbx.cbTipoDocumento()));

                //Tmp
                cbParentesco.setModel(new javax.swing.DefaultComboBoxModel(cbx.cbParentesco()));


                //Configura la Interfaz para el Modo en el que fue invocado
                configModo((String) e[1], (String) e[2]);

                //Setear Migas de Pan
                c.setNavegar("Paciente_View_Grid");
                // Indicar a las 'migas de pan' donde estamos.
                c.setLabelModulo("Pacientes");


            } catch (Exception exc) {
                System.err.println("(config())Error de Asignacion , compruebe el numero de Parametros que envia .. " + exc.getMessage());
                exc.printStackTrace();
            }
        }
    }

    public void cargar(Map<String, String> dato) {
        idAcuediente = dato.get("CODIGO");
        cNombreAcuediente.setText(dato.get("NOMBRES"));
        cTelAcuediente.setText(dato.get("TELEFONO"));
        cDirAcuediente.setText(dato.get("DIRECCION"));
    }

    void prepararTransaccion() {

        String tablaBD = "paciente";
//        
//        tabla = "identificacion=55[req-num(0,20)]";

        StringBuilder sqlAndRestricciones = new StringBuilder();
        StringBuilder camposBD = new StringBuilder();
        StringBuilder valoresBD = new StringBuilder();

        sqlAndRestricciones.append("Tipo Documento@id_tipodocumento='" + cbx.getKeyTipoDocumento(cbTipoDocumento) + "'[-(0,0)]&");
        sqlAndRestricciones.append("Numero Identificacion@identificacion='" + cIdentificacion.getText().toLowerCase() + "'[req-num(6,12)UNQ" + noIdentificacion + "]&");
        sqlAndRestricciones.append("Nombre Paciente@nombres='" + cNombres.getText().toLowerCase() + "'[req-txt(0,60)]&");
        sqlAndRestricciones.append("Apellido Paciente@apellidos='" + cApellidos.getText().toLowerCase() + "'[req-txt(0,60)]&");
        sqlAndRestricciones.append("Direccion Paciente@direccion='" + cDireccion.getText().toLowerCase() + "'[-(0,120)]&");
        sqlAndRestricciones.append("Numero de Telefono@telefono=" + cTelefono.getText().toLowerCase() + "[-num(7,15)]&");
        sqlAndRestricciones.append("Ciudad de Residencia@id_ciudad=" + cbx.getKeyMun(cbCiudad) + "[-(0,0)]&");
        sqlAndRestricciones.append("Religión@religion='" + cReligion.getText().toLowerCase() + "'[-txt(0,50)]&");
        sqlAndRestricciones.append("Estrato Socio Economico@estrato=" + sEstrato.getValue().toString() + "[-(0,1)]&");
        sqlAndRestricciones.append("Sexo@id_sexo='" + cbx.getKeySexo(cbSexo) + "'[-(0,0)]&");
        sqlAndRestricciones.append("Acuendiente@id_acudiente=" + idAcuediente + "[req-num(0,0)]&");
        sqlAndRestricciones.append("Parentesco Acudiente@id_parentesco=" + cbx.getKeyParentesco(cbParentesco) + "[req-num(0,0)]&");
        sqlAndRestricciones.append("Fecha Nacimiento@fecha_nacimiento=" + u.fechaToString(cFechaNacimiento.getDate(), true) + "[req-fecha(0,0)]&");
        sqlAndRestricciones.append("Fecha Ingreso@fecha_ingreso=" + u.fechaToString(cFechaIngreso.getDate(), true) + "[req-fecha-(0,0)]");

        String mensajeUsuario = controlador.prepararTransaccion(tablaBD, sqlAndRestricciones, mod, "El Paciente", campoPK);

        c.informarUsuario(mensajeUsuario);

        //Asignar el Nuevo valor al Campo Identificacion (Unique Campos)
        noIdentificacion = cIdentificacion.getText().toLowerCase();

    }

    private void configModo(String m, String key) {
        mod = m;
        String SQL_BUSCAR = String.format("SELECT pac.id_paciente , tipdoc.descripcion , pac.identificacion, pac.nombres , pac.apellidos , pac.direccion , pac.telefono , ciu.nombre_ciudad , depto.nombre_dep  , pac.fecha_nacimiento , pac.fecha_ingreso , pac.religion , pac.estrato , sex.descripcion , par.nombre ,"
                + " UPPER(acu.nombres||' '||acu.apellidos), acu.telefono , UPPER(acu.direccion) , acu.id_acudiente "
                + " FROM paciente pac , tipodocumento tipdoc , ciudad ciu , departamentos depto , sexo sex , parentesco par , acudiente acu "
                + " WHERE tipdoc.id_tipodocumento = pac.id_tipodocumento AND pac.id_ciudad = ciu.id_ciudad AND ciu.id_depto = depto.id_departamento AND sex.id_sexo  = pac.id_sexo AND par.id_parentesco = pac.id_parentesco"
                + " AND acu.id_acudiente = pac.id_acudiente AND pac.estado = 1 AND pac.id_paciente = %s", key);

        if (!mod.equals("")) {

            if ("INSERT".equals(mod)) {
                c.setLabelAccion("Agregar Paciente");
            }

            if (!mod.equals("INSERT")) {
                setLlavePrimaria(key);
                c.setLabelAccion("Crear Nuevo Paciente");

                campoPK = "id_paciente = " + getLlavePrimaria();
            }

            if (mod.equals("SELECT")) {
                System.out.println("mod = " + mod);
                //System.out.println("key = " + key);
                estadoComponentes(false);
                c.setLabelAccion("Consulta Paciente");
                setPaciente(controlador.buscar(SQL_BUSCAR));

            } else if (mod.equals("UPDATE")) {
                System.out.println("mod = " + mod);
                System.out.println("key = " + key);

                estadoComponentes(true);

                c.setLabelAccion("Modiciar Paciente");
                setPaciente(controlador.buscar(SQL_BUSCAR));
                bGuardar.setText("Actualizar");
                //Cambiar icono here...

                //Tomar cuando arranque la pantalla los campos UNQ
                noIdentificacion = cIdentificacion.getText();
                System.out.println("noIdentificacion = " + noIdentificacion);
            }

        }
    }

    public String getLlavePrimaria() {
        return llavePrimaria;
    }

    public void setLlavePrimaria(String llavePrimaria) {
        this.llavePrimaria = llavePrimaria;
    }

    void estadoComponentes(Boolean estado) {
        //Aqui Componentes 
    }

    private void setPaciente(Object[][] paciente) {
        cbTipoDocumento.setSelectedItem(paciente[0][1].toString());
        cIdentificacion.setText(paciente[0][2].toString());
        cNombres.setText(paciente[0][3].toString());
        cApellidos.setText(paciente[0][4].toString());
        cDireccion.setText(paciente[0][5].toString());
        cTelefono.setText(paciente[0][6].toString());
        cbDepto.setSelectedItem(paciente[0][8].toString());
        System.out.println("paciente[0][8].toString() = " + paciente[0][8].toString());
        cbCiudad.setSelectedItem(paciente[0][7].toString());
        System.out.println("paciente[0][7].toString() = " + paciente[0][7].toString());
        cFechaNacimiento.setDate(u.stringToDate(paciente[0][9].toString()));
        cFechaIngreso.setDate(u.stringToDate(paciente[0][10].toString()));
        cReligion.setText(paciente[0][11].toString());
        sEstrato.setValue(Integer.parseInt(paciente[0][12].toString()));
        cbSexo.setSelectedItem(paciente[0][13].toString());
        cbParentesco.setSelectedItem(paciente[0][14].toString());
        cNombreAcuediente.setText(paciente[0][15].toString());
        cTelAcuediente.setText(paciente[0][16].toString());
        cDirAcuediente.setText(paciente[0][17].toString());
        idAcuediente = paciente[0][18].toString();
    }
}
